<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">

    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
    </div>

    <!-- table区域-begin -->
    <div>

      <a-table
        ref="table"
        size="middle"
        :scroll="{x:scrollX}"
        :components="draggableComponent"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        class="j-table-force-nowrap"
        :customRow="customRow"
        @change="handleTableChange">
        <template slot="status" slot-scope="status">
          <a-badge :status="status | statusTypeFilter" :text="status | statusFilter"/>
        </template>
        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>

      </a-table>
    </div>

    <erp-omc-platform-account-final-modal ref="modalForm" @ok="modalFormOk"></erp-omc-platform-account-final-modal>
    <audit-modal ref="auditModal" @ok="modalFormOk"></audit-modal>

  </a-card>
</template>

<script>

import '@/assets/less/TableExpand.less'
import { mixinDevice } from '@/utils/mixin'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import { getAction } from '@/api/manage'
import ErpOmcPlatformAccountFinalModal from './modules/ErpOmcPlatformAccountFinalModal'
import { DisabledAuthFilterMixin } from '@/mixins/DisabledAuthFilterMixin'
import SelectUserByDep from '@/views/scy/components/SelectUserByDep'

export default {
  name: 'ErpOmcPlatformAccountFinalList',
  mixins: [JeecgListMixin, mixinDevice, DisabledAuthFilterMixin],
  components: {
    ErpOmcPlatformAccountFinalModal,
    SelectUserByDep
  },
  props: {
    disabledButton: {
      type: Boolean,
      default: false,
    }
  },
  data() {
    return {
      description: '平台账号档案管理页面',
      //表头
      columns: [],
      //列设置
      settingColumns: [],
      loading: false,
      // 列定义
      defColumns: [
        {
          title: '序号',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: function (t, r, index) {
            return parseInt(index) + 1;
          }
        },
        {
          title: '单据编号',
          align: 'center',
          dataIndex: 'ptzhbm',
          ellipsis: true,
          width: 105,
        },
        {
          title: '平台名称',
          align: 'center',
          dataIndex: 'ptmc',
          ellipsis: true,
          width: 105,
        },
        {
          title: '会员单位',
          align: 'center',
          dataIndex: 'hydw',
          ellipsis: true,
          width: 105,
        },
        {
          title: '保管人',
          align: 'center',
          dataIndex: 'bgr_dictText',
          ellipsis: true,
          width: 105,
        },
        {
          title: '网址',
          align: 'center',
          dataIndex: 'wz',
          ellipsis: true,
          width: 105,
        },
        {
          title: '登录名',
          align: 'center',
          dataIndex: 'dlm',
          ellipsis: true,
          width: 105,
        },
        {
          title: '密码',
          align: 'center',
          dataIndex: 'mm',
          ellipsis: true,
          width: 105,
        },
        {
          title: '会员等级',
          align: 'center',
          dataIndex: 'hydj',
          ellipsis: true,
          width: 105,
        },
        {
          title: '会员有效期始',
          align: 'center',
          ellipsis: true,
          width: 105,
          dataIndex: 'hyyxqs',
          customRender: function (text) {
            return !text ? '' : (text.length > 10 ? text.substr(0, 10) : text)
          }
        },
        {
          title: '会员有效期止',
          align: 'center',
          ellipsis: true,
          width: 105,
          dataIndex: 'hyyxqe',
          customRender: function (text) {
            return !text ? '' : (text.length > 10 ? text.substr(0, 10) : text)
          }
        },
        {
          title: 'ca锁密码',
          align: 'center',
          ellipsis: true,
          width: 105,
          dataIndex: 'casmm',
        },
        {
          title: 'ca锁个数',
          align: 'center',
          ellipsis: true,
          width: 105,
          dataIndex: 'casgs'
        },
        {
          title: '申请人',
          align: 'center',
          ellipsis: true,
          width: 105,
          dataIndex: 'handlerId_dictText'
        },
        {
          title: '申请部门',
          ellipsis: true,
          width: 105,
          align: 'center',
          dataIndex: 'handlerDeptId_dictText'
        },
        {
          title: '申请类型',
          ellipsis: true,
          width: 105,
          align: 'center',
          dataIndex: 'lx_dictText'
        },
        {
          title: '状态',
          align: 'center',
          dataIndex: 'bpmStatus_dictText',
          ellipsis: true,
          width: 105,
        },
      ],
      url: {
        list: '/api/erp/omc/platformaccount/erpOmcPlatformAccount/list',
        list0: '/api/erp/omc/platformaccount/erpOmcPlatformAccount/list?plfId=',
        delete: '/api/erp/omc/platformaccount/erpOmcPlatformAccountFinal/delete',
        deleteBatch: '/api/erp/omc/platformaccount/erpOmcPlatformAccountFinal/deleteBatch',
        exportXlsUrl: '/api/erp/omc/platformaccount/erpOmcPlatformAccountFinal/exportXls',
        importExcelUrl: 'api/erp/omc/platformaccount/erpOmcPlatformAccountFinal/importExcel',
        submit: '/api/erp/omc/platformaccount/erpOmcPlatformAccountFinal/submit',
        submitBatch: '/api/erp/omc/platformaccount/erpOmcPlatformAccountFinal/submitBatch',
        revoke: '/api/erp/omc/platformaccount/erpOmcPlatformAccountFinal/revoke',
        revokeBatch: '/api/erp/omc/platformaccount/erpOmcPlatformAccountFinal/revokeBatch',
        counterTrial: '/api/erp/omc/platformaccount/erpOmcPlatformAccountFinal/counterTrial',
        counterTrialBatch: '/api/erp/omc/platformaccount/erpOmcPlatformAccountFinal/counterTrialBatch',
        audit: '/api/erp/omc/platformaccount/erpOmcPlatformAccountFinal/audit',
        auditBatch: '/api/erp/omc/platformaccount/erpOmcPlatformAccountFinal/auditBatch',
        overrule: '/api/erp/omc/platformaccount/erpOmcPlatformAccountFinal/overrule',
        overruleBatch: '/api/erp/omc/platformaccount/erpOmcPlatformAccountFinal/overruleBatch',
      },
      dictOptions: {},
      superFieldList: [],
      disableMixinCreated: true,

    }
  },
  watch: {
    $route(to, from) {
      this.url.list = this.url.list0 + this.$route.params.id;
      //this.url.exportXlsUrl = this.url.exportXlsUrl0 + this.$route.params.id;
      // this.url.importExcelUrl = this.url.importExcelUrl0 + this.$route.params.id;
      this.loadData();
    },
  },
  created() {
    this.getSuperFieldList();
    this.url.list = this.url.list0 + this.$route.params.id;
    this.loadData()
    this.initColumns();
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
    },
  },
  methods: {
    handleDetail: function (record) {
      const _path = this.$route.path
      if (_path.startsWith('/hmhb/') || _path.startsWith('/scy/') || _path.startsWith('/imp/')
        || _path.startsWith('/erp/')) {
        this.$router.push({
          path: `/erp/omc/platformaccount/ErpOmcPlatformAccountListDetail/${record.id}`
        })
      } else {
        this.$refs.modalForm.edit(record);
        this.$refs.modalForm.title = '详情';
        this.$refs.modalForm.disableSubmit = true;
      }
    },
    loadData(arg) {

      //debugger;
      this.url.list = this.url.list0 + this.$route.params.id;

      if (!this.url.list) {
        this.$message.error('请设置url.list属性!')
        return
      }
      // 加载数据 若传入参数1则加载第一页的内容
      if (arg === 1) {
        this.ipagination.current = 1
      }
      var params = this.getQueryParams() // 查询条件
      this.loading = true
      getAction(this.url.list, params).then(res => {
        if (res.success) {
          // update-begin---author:zhangyafei    Date:20201118  for：适配不分页的数据列表------------
          this.dataSource = res.result.records || res.result
          if (res.result.total) {
            this.ipagination.total = res.result.total
          } else {
            this.ipagination.total = 0
          }
          //判断是否当前页没有数据且不为第一页
          if (this.dataSource.length == 0 && this.ipagination.current != 1) {
            this.ipagination.current = this.ipagination.current - 1
            this.loadData(this.ipagination.current - 1);
          }
          // update-end---author:zhangyafei    Date:20201118  for：适配不分页的数据列表------------
        }
        if (res.code === 510) {
          this.$message.warning(res.message)
        }
        this.loading = false
      })
    },
    initDictConfig() {
    },
    getSuperFieldList() {
      let fieldList = [];
      fieldList.push({ type: 'string', value: 'mm', text: '密码', dictCode: '' })
      fieldList.push({ type: 'int', value: 'casgs', text: 'ca锁个数', dictCode: '' })
      fieldList.push({ type: 'string', value: 'wz', text: '网址', dictCode: '' })
      fieldList.push({ type: 'string', value: 'dlm', text: '登录名', dictCode: '' })
      fieldList.push({ type: 'string', value: 'hydj', text: '会员等级', dictCode: '' })
      fieldList.push({ type: 'date', value: 'casyxqs', text: 'ca锁有效期始' })
      fieldList.push({ type: 'date', value: 'hyyxqs', text: '会员有效期始' })
      fieldList.push({ type: 'string', value: 'ptmc', text: '平台名称', dictCode: '' })
      fieldList.push({ type: 'string', value: 'jbbm', text: '经办部门', dictCode: '' })
      fieldList.push({ type: 'date', value: 'casyxqe', text: 'ca锁有效期止' })
      fieldList.push({ type: 'string', value: 'hydw', text: '会员单位', dictCode: '' })
      fieldList.push({ type: 'string', value: 'casmm', text: 'ca锁密码', dictCode: '' })
      fieldList.push({ type: 'string', value: 'bz', text: '备注', dictCode: '' })
      fieldList.push({ type: 'string', value: 'jbr', text: '经办人', dictCode: '' })
      fieldList.push({ type: 'date', value: 'hyyxqe', text: '会员有效期止' })
      fieldList.push({ type: 'string', value: 'auditStatus', text: '状态', dictCode: '' })
      fieldList.push({ type: 'string', value: 'ptzhbm', text: '平台账号编码', dictCode: '' })
      fieldList.push({ type: 'string', value: 'bgr', text: '保管人', dictCode: '' })
      this.superFieldList = fieldList
    }
  }
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>
